﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CC98.Network
{
    public static class UrlEncoding
    {
        public static Dictionary<string, string> Decode(string content)
        {
            var plainContent = Uri.UnescapeDataString(content);
            Dictionary<string,string> resultDict = new Dictionary<string,string>();

            foreach (var kvContent in plainContent.Split('&'))
            {
                var kvPair = kvContent.Split('=');
                if (kvPair.Length < 2)
                    resultDict[kvPair[0]] = string.Empty;
                else
                    resultDict[kvPair[0]] = kvPair[1];
            }

            return resultDict;
        }
    }
}
